<?php
declare (strict_types = 1);

namespace app\index\controller;

use app\BaseController;
use think\facade\Db;
use think\facade\Request;
use think\facade\View;

class Index extends BaseController
{


    public function index()
    {
        //[请求接参]
        //parameter
        //规则：变量分类方法('变量名/变量修饰符','默认值','过滤方法')
        //变量类型方法：param(只接受pathinfo的参数)|get(只接？传参)|post(只接表单传参)
        //变量名/变量修饰符：指定变量接参
//                          指定接收全部参数param(); 不写任何参数;param接参最后生效，会覆盖get的参数
        //                  变量修饰符时对变量强制类型转换：

        //修饰符           作用
        //s                强制转换为字符串类型
        //d                强制转换为整型类型
        //b                强制转换为布尔类型
        //a                强制转换为数组类型
        //f                强制转换为浮点类型
        //默认值    param     只要变量没有赋值或者传递值，就会启动默认值
        //         get、post  变量值、变量名都不存在时，才启用默认值
        //过滤方法：在接参后自动执行过滤方法(对应的同名函数，只有一个形参)，对参数进行过滤或者转义；
        //          trim:去掉两端空格：
        //          htmlspecialchars:对常见的五个字符进行转义(内容保留，但失去了原本的功效)   & => $amp;   < => $lt;   > => $gt;   ' => '   " => $quot;`
        //          strip_tags: 对常见的html、php以及NULL标签进行过滤；（干掉了）

        echo Request::host();
        echo "<br>";
        echo Request::scheme();
        echo "<br>";
        echo Request::port();
        echo "<br>";
        echo Request::remotePort();
        echo "<br>";
        echo Request::protocol();
        echo "<br>";
        echo Request::contentType();
        echo "<br>";
        echo Request::domain();
        echo "<br>";
        echo Request::subDomain();
        echo "<br>";
        echo Request::panDomain();
        echo "<br>";
        echo Request::rootDomain();
        echo "<br>";
        echo Request::url();
        echo "<br>";
        echo Request::baseUrl();
        echo "<br>";
        echo Request::query();
        echo "<br>";
        echo Request::baseFile();
        echo "<br>";
        echo Request::root();
        echo "<br>";
        echo Request::rootUrl();
        echo "<br>";
        echo Request::pathinfo();
        echo "<br>";
        echo Request::ext();
        echo "<br>";
        echo Request::time();
        echo "<br>";
        echo Request::type();
        echo "<br>";
//        echo Request::rule();     报错
//        echo "<br>";

        //判断
        echo Request::method();
        echo "<br>";
        echo Request::isGet();
        echo "<br>";
        echo Request::isPost();
        echo "<br>";
        echo Request::isPut();
        echo "<br>";
        echo Request::isDelete();
        echo "<br>";
        echo Request::isAjax();
        echo "<br>";
        echo Request::isJson();
        echo "<br>";
        echo Request::isMobile();
        echo "<br>";
        echo Request::isHead();
        echo "<br>";
        echo Request::isPatch();
        echo "<br>";
        echo Request::isOptions();
        echo "<br>";
        echo Request::isCli();
        echo "<br>";
        echo Request::isCgi();





//        echo Request::post('username',100,'trim,htmlspecialchars,strip_tags');
//
//        echo "<pre>";
//        print_r(Request::post('','','trim,htmlspecialchars,strip_tags'));
//        echo "</pre>";
//
//        echo "<pre>";
//        print_r($_POST);
//        echo "</pre>";
//
//        var_dump(Request::post('','','trim,htmlspecialchars,strip_tags'));
//        var_dump($_POST);

//        var_dump(Request::get('id',100)) ;
//        var_dump(Request::post('keyword',100));
//
//        echo "<pre>";
//        print_r($_GET);
//        echo "</pre>";
//
//        echo "<pre>";
//        print_r($_POST);
//        echo "</pre>";

////        echo Request::param('id');
//            echo "<pre>";
//            print_r(Request::param());
//            echo "</pre>";
////        echo Request::baseUrl();
//        $hobby = Request::post('hobby/a'); //多个同名的复选框传参为数组
//        var_dump($hobby);
//        echo "<pre>";
//        print_r($_GET);
//        echo "</pre>";
    }
    public function qaz()
    {
        $arr=Db::table('goods')->field('spname')->where('id',2)->find();
        echo "<pre>";
        print_r($arr);
        echo "</pre>";
        $arr2=Db::table('goods')->where('id',3)->select();
        echo "<pre>";
        print_r($arr2);
        echo "</pre>";
    }


    public function text()
    {
        $arr = array();
        $arr[] = array('id'=>'1','title'=>'中国女排再次夺冠','content'=>'中国女排再次夺冠...............','type'=>'体育');
        $arr[] = array('id'=>'2','title'=>'天津大爆炸','content'=>'天津大爆炸...............','type'=>'社会');
        $arr[] = array('id'=>'3','title'=>'好声音','content'=>'好声音...............','type'=>'娱乐');
        $arr[] = array('id'=>'4','title'=>'中国股市如过山车','content'=>'中国股市如过山车...............','type'=>'竞技');
        $arr[] = array('id'=>'5','title'=>'中国女排再次夺冠','content'=>'中国女排再次夺冠...............','type'=>'体育');
        $arr[] = array('id'=>'6','title'=>'天津大爆炸','content'=>'天津大爆炸...............','type'=>'社会');
        $arr[] = array('id'=>'7','title'=>'好声音','content'=>'好声音...............','type'=>'娱乐');
        $arr[] = array('id'=>'8','title'=>'中国股市如过山车','content'=>'中国股市如过山车...............','type'=>'竞技');

        View::fetch('arr',$arr);
        return View::fetch();
    }
    public function frm(){
        return View::fetch();
    }
}
